Module: ToFactory

Defined in:
lib/to_factory.rb,
lib/to_factory/config.rb,
lib/to_factory/version.rb,
lib/to_factory/collation.rb,
lib/to_factory/file_sync.rb,
lib/to_factory/file_writer.rb,
lib/to_factory/parsing/file.rb,
lib/to_factory/finders/model.rb,
lib/to_factory/options_parser.rb,
lib/to_factory/parsing/syntax.rb,
lib/to_factory/representation.rb,
lib/to_factory/finders/factory.rb,
lib/to_factory/klass_inference.rb,
lib/to_factory/generation/factory.rb,
lib/to_factory/parsing/new_syntax.rb,
lib/to_factory/parsing/old_syntax.rb,
lib/to_factory/generation/attribute.rb

Defined Under Namespace

Modules: Finders, Generation, Parsing Classes: CannotInferClass, Collation, FileSync, FileWriter, KlassInference, MissingActiveRecordInstanceException, NotFoundError, OptionsParser, Representation

Constant Summary collapse

VERSION =
"0.2.1"
AlreadyExists =
Class.new ArgumentError

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.factoriesObject

Returns the value of attribute factories.



3
4
5
# File 'lib/to_factory/config.rb', line 3

def factories
  @factories
end

.modelsObject

Returns the value of attribute models.



3
4
5
# File 'lib/to_factory/config.rb', line 3

def models
  @models
end

Class Method Details

.definition_for(item) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/to_factory.rb', line 33

def definition_for(item)
  if item.is_a? ActiveRecord::Base
    Representation.from(item).definition
  else
    if found = representations.find{|r| r.name.to_s == item.to_s }
      found.definition
    else
      raise NotFoundError.new "No definition found for #{item}"
    end
  end
end

.definitionsObject



45
46
47
# File 'lib/to_factory.rb', line 45

def definitions
  representations.map(&:name)
end

.new_syntax?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
# File 'lib/to_factory.rb', line 22

def new_syntax?
  require "factory_girl"
  if FactoryGirl::VERSION.to_s[0..0].to_i > 1
    true
  else
    false
  end
rescue NameError, ArgumentError
  false
end

.representationsObject



49
50
51
# File 'lib/to_factory.rb', line 49

def representations
  Finders::Factory.new.call
end

.reset_config!Object



5
6
7
8
# File 'lib/to_factory/config.rb', line 5

def reset_config!
  @factories = nil
  @models = nil
end