Skip to content

Commit

Permalink
Merge pull request #443 from decko-commons/unrequire
Browse files Browse the repository at this point in the history
try new autoloading approach
  • Loading branch information
ethn authored Feb 11, 2020
2 parents 08e81aa + 5ab3e7a commit 77635f1
Show file tree
Hide file tree
Showing 45 changed files with 28 additions and 173 deletions.
3 changes: 1 addition & 2 deletions card/config/initializers/recaptcha.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ def load_recaptcha_card_config setting
Recaptcha.configure do |config|
# the seed task runs initializers so we have to check
# if the cards table is ready before we use it here
CONFIG_OPTIONS = %i[site_key secret_key]
if card_table_ready?
CONFIG_OPTIONS.each do |setting|
%i[site_key secret_key].each do |setting|
config.send "#{setting}=", load_recaptcha_config(setting)
end
end
Expand Down
3 changes: 0 additions & 3 deletions card/db/migrate/20110511221913_require_earlier_migrations.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- encoding : utf-8 -*-

require "card/version"

class RequireEarlierMigrations < ActiveRecord::Migration[4.2]
def self.up
raise %(
Expand Down
1 change: 0 additions & 1 deletion card/db/test_seed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

# noinspection RubyResolve
class SharedData
require_relative "../lib/card/model/save_helper"
extend Card::Model::SaveHelper

USERS = [
Expand Down
25 changes: 2 additions & 23 deletions card/lib/card.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- encoding : utf-8 -*-

require "application_record"

ActiveSupport.run_load_hooks(:before_card, self)

# Cards are wiki-inspired building blocks.
Expand Down Expand Up @@ -94,31 +92,11 @@
#
# {Card::Auth More on accounts}
class Card < ApplicationRecord
require "card/env"
require "card/mark"
extend ::Card::Mark

require "card/dirty"
extend ::Card::Dirty::MethodFactory
include ::Card::Dirty

require "card/name"
require "card/codename"
require "card/query"
require "card/format"
require "card/error"
require "card/auth"
require "card/mod"
require "card/content"
require "card/action"
require "card/act"
require "card/change"
require "card/reference"
require "card/subcards"
require "card/view"
require "card/act_manager"
require "card/layout"
require "card/set"
Card::Cache

has_many :references_in, class_name: :Reference, foreign_key: :referee_id
has_many :references_out, class_name: :Reference, foreign_key: :referer_id
Expand Down Expand Up @@ -189,3 +167,4 @@ def serializable_attributes

ActiveSupport.run_load_hooks(:card, self)
end
ActiveSupport.run_load_hooks :after_card, self
3 changes: 0 additions & 3 deletions card/lib/card/act_manager.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require "card/act_manager/stage_director"
require "card/act_manager/event_delay"

class Card
# Manages the whole process of creating an {act Card::Act} ie. changing
# a card and attached subcards.
Expand Down
3 changes: 0 additions & 3 deletions card/lib/card/act_manager/stage_director.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class ActManager
# then the subcard's store stage is executed before the supercard's store
# stage
class StageDirector
require "card/act_manager/stage"
require "card/act_manager/stage_director/phases"

include Stage
include Phases

Expand Down
5 changes: 0 additions & 5 deletions card/lib/card/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ class Card
# Manages current user,
# "as" user, and password verification.
module Auth
require "card/auth/permissions"
require "card/auth/proxy"
require "card/auth/setup"
require "card/auth/current"

extend Permissions
extend Proxy
extend Setup
Expand Down
1 change: 0 additions & 1 deletion card/lib/card/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def cache
# directly, because caching is automatically handled by Card#fetch
#
class Cache
require "card/cache/prepopulate"
extend Card::Cache::Prepopulate

@@cache_by_class = {}
Expand Down
1 change: 0 additions & 1 deletion card/lib/card/codename.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class Card
# Every process maintains a complete cache that is not frequently reset
#
class Codename
require "card/cache"
class << self
# returns codename for id and id for codename
# @param codename [Integer, Symbol, String, Card::Name]
Expand Down
12 changes: 4 additions & 8 deletions card/lib/card/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ class Card
# Each chunk has an object whose class inherits from {Card::Content::Chunk::Abstract}
#
class Content < SimpleDelegator
# ActiveSupport::Dependencies::ModuleConstMissing.include_into(self)
require "card/content/clean"
require "card/content/truncate"
require "card/content/chunk"
require "card/content/parser"

extend ::Card::Content::Clean
extend ::Card::Content::Truncate
extend Clean
extend Truncate

Chunk

attr_reader :revision, :format, :chunks, :opts

Expand Down
2 changes: 0 additions & 2 deletions card/lib/card/content/chunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class Content < SimpleDelegator
# match by its pattern.
#
module Chunk
require "card/content/chunk/abstract"

mattr_accessor :raw_list, :prefix_regexp_by_list,
:prefix_map_by_list, :prefix_map_by_chunkname
@@raw_list = {}
Expand Down
1 change: 0 additions & 1 deletion card/lib/card/dirty.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Card
module Dirty
require "card/dirty/method_factory"
extend ::Card::Dirty::MethodFactory

%i[name db_content trash type_id].each do |field|
Expand Down
3 changes: 0 additions & 3 deletions card/lib/card/env.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require "card/env/location"
require "card/env/location_history"

class Card
# Card::Env is a module for containing the variable details of the environment
# in which Card operates.
Expand Down
8 changes: 0 additions & 8 deletions card/lib/card/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ class Card
# these format classes.
#
class Format
require "card/format/registration"
require "card/format/nesting"
require "card/format/render"
require "card/format/context_names"
require "card/format/content"
require "card/format/error"
require "card/format/method_delegation"

extend ActiveSupport::Autoload
extend Registration

Expand Down
2 changes: 0 additions & 2 deletions card/lib/card/format/nest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ class Card
class Format
# processing nests
class Nest
require "card/format/nest/fetch"

include Fetch

attr_accessor :format, :card, :view, :view_opts, :format_opts
Expand Down
4 changes: 0 additions & 4 deletions card/lib/card/format/nesting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ class Card
class Format
# the core of the nesting api
module Nesting
require "card/format/nesting/main"
require "card/format/nesting/subformat"
require "card/format/nesting/mode"

include Main
include Subformat
include Mode
Expand Down
3 changes: 0 additions & 3 deletions card/lib/card/mod.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ class Card
# - **chunk** provides tools for finding new patterns in card content
# - **file** for fixed initial card content
module Mod
require "card/mod/loader"
require "card/mod/dirs"

class << self
def load
return if ENV["CARD_MODS"] == "none"
Expand Down
4 changes: 2 additions & 2 deletions card/lib/card/mod/loader/set_pattern_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def to_const
return Object if simple_load?

Card::Set.const_get_or_set(@pattern.camelize) do
Class.new(Card::Set::Pattern::Abstract)
Class.new(Card::Set::Pattern::Base)
end
end

Expand All @@ -34,7 +34,7 @@ def auto_comment
end

def module_chain
"class Card::Set::#{@pattern.camelize} < Card::Set::Pattern::Abstract"
"class Card::Set::#{@pattern.camelize} < Card::Set::Pattern::Base"
end

def preamble_bits
Expand Down
6 changes: 1 addition & 5 deletions card/lib/card/mod/module_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ def build

# @return [String] the ruby code to build the modal
def to_s
if simple_load?
@content
else
processed_content
end
simple_load? ? @content : processed_content
end

def processed_content
Expand Down
5 changes: 1 addition & 4 deletions card/lib/card/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ class Card
#
# Card::Name adds support for deeper card integration
class Name < Cardname
require "card/name/fields_and_traits"
require "card/name/name_variants"

include FieldsAndTraits
include ::Card::Name::NameVariants
include NameVariants

self.params = Card::Env # yuck!
self.session = proc { Card::Auth.current.name } # also_yuck
Expand Down
3 changes: 0 additions & 3 deletions card/lib/card/query/abstract_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ module Query
#
# See AbstractQuery::Tie for more on how tables can be connected.
class AbstractQuery
require "card/query/abstract_query/query_helper"
require "card/query/abstract_query/tie"

include QueryHelper
include Tie

Expand Down
12 changes: 0 additions & 12 deletions card/lib/card/query/card_query.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
class Card
module Query
# interpret CQL queries, transform them into SQL, and run them.
require "card/query/abstract_query"

class CardQuery < AbstractQuery
require "card/query/card_query/run"
require "card/query/card_query/match_attributes"
require "card/query/card_query/relational_attributes"
require "card/query/card_query/reference_attributes"
require "card/query/card_query/found_by"
require "card/query/card_query/interpretation"
require "card/query/card_query/normalization"
require "card/query/card_query/sorting"
require "card/query/card_query/conjunctions"

include Clause
include Run
include MatchAttributes
Expand Down
6 changes: 6 additions & 0 deletions card/lib/card/set/abstract.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Card
module Set
class Abstract < Pattern::Base
end
end
end
2 changes: 0 additions & 2 deletions card/lib/card/set/advanced_api.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'card/dirty'

class Card
module Set
# advanced set module API
Expand Down
4 changes: 0 additions & 4 deletions card/lib/card/set/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ module Set
# Events can be defined on each of these stages
#
class Event
require "card/set/event/delayed_event"
require "card/set/event/options"
require "card/set/event/callbacks"

module Api
def event event, stage_or_opts={}, opts={}, &final
Event.new(event, stage_or_opts, opts, self, &final).register
Expand Down
5 changes: 0 additions & 5 deletions card/lib/card/set/format/abstract_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ module Format
# Whenever you create a format block in a set module in a {Card::Mod mod}, you
# create a format module that is extended with AbstractFormat.
module AbstractFormat
require "card/set/format/abstract_format/view_opts"
require "card/set/format/abstract_format/view_definition"
require "card/set/format/abstract_format/haml_views"
require "card/set/format/abstract_format/wrapper"

include Set::Basket
include ViewOpts
include ViewDefinition
Expand Down
3 changes: 0 additions & 3 deletions card/lib/card/set/pattern.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
class Card
module Set
class Pattern
require "card/set/type"
# ::Card::Set::Type

class << self
def reset
nonbase_loadables.each do |set_pattern|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class Card
module Set
class Pattern
class Abstract
# class from which set patterns inherit
class Base
class << self
attr_accessor :pattern_code, :pattern_id, :junction_only,
:assigns_type, :anchorless
Expand All @@ -27,7 +28,7 @@ def junction_only?
end

def anchorless?
!!anchorless
anchorless
end

def pattern
Expand Down Expand Up @@ -58,18 +59,13 @@ def generic_label
# Instance methods

def initialize card
unless self.class.anchorless?
@anchor_name = self.class.anchor_name(card).to_name
@anchor_id = find_anchor_id card
end
return if self.class.anchorless?
@anchor_name = self.class.anchor_name(card).to_name
@anchor_id = find_anchor_id card
end

def find_anchor_id card
if self.class.respond_to? :anchor_id
self.class.anchor_id card
else
Card.fetch_id @anchor_name
end
self.class.try(:anchor_id, card) || Card.fetch_id(@anchor_name)
end

def module_key
Expand Down Expand Up @@ -127,11 +123,7 @@ def inspect

def safe_key
caps_part = self.class.pattern_code.to_s.tr(" ", "_").upcase
if self.class.anchorless?
caps_part
else
"#{caps_part}-#{@anchor_name.safe_key}"
end
self.class.anchorless? ? caps_part : "#{caps_part}-#{@anchor_name.safe_key}"
end

def rule_set_key
Expand All @@ -145,4 +137,3 @@ def rule_set_key
end
end
end

2 changes: 1 addition & 1 deletion card/lib/card/set/type.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Card
module Set
class Type < Pattern::Abstract
class Type < Pattern::Base
def initialize card
super
# support type inheritance
Expand Down
Loading

0 comments on commit 77635f1

Please sign in to comment.