Class: AnswerFactory::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/factories/factory.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Factory

Returns a new instance of Factory.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/factories/factory.rb', line 13

def initialize(options = {})
  
  # Factory instance settings
  @name = options[:name] ||
    configatron.factory.retrieve(:name,nil) ||
    "my_factory"
  
  @workstation_names = options[:workstation_names] ||
    configatron.factory.retrieve(:workstation_names, nil) ||
    Array.new
  
  
  # CouchDB settings
  @couchdb_server = options[:couchdb_server] ||
    configatron.factory.couchdb.retrieve(:server, nil) ||
    "http://127.0.0.1:5984"
    
    
  
  @couchdb_name = options[:couchdb_name] ||
    configatron.factory.couchdb.retrieve(:name, nil) ||
    @name
  
  
  # Nudge language settings
  @nudge_instructions = options[:nudge_instructions] ||
    configatron.nudge.instructions.retrieve(:all, nil) ||
    Instruction.all_instructions
  
  @nudge_types = options[:nudge_types] ||
    configatron.nudge.types.retrieve(:all, nil) ||
    NudgeType.all_types
  
  update_configatron!
end

Instance Attribute Details

#couchdb_nameObject (readonly)

Returns the value of attribute couchdb_name.



8
9
10
# File 'lib/factories/factory.rb', line 8

def couchdb_name
  @couchdb_name
end

#couchdb_serverObject (readonly)

Returns the value of attribute couchdb_server.



8
9
10
# File 'lib/factories/factory.rb', line 8

def couchdb_server
  @couchdb_server
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/factories/factory.rb', line 5

def name
  @name
end

#nudge_instructionsObject (readonly)

Returns the value of attribute nudge_instructions.



6
7
8
# File 'lib/factories/factory.rb', line 6

def nudge_instructions
  @nudge_instructions
end

#nudge_typesObject (readonly)

Returns the value of attribute nudge_types.



7
8
9
# File 'lib/factories/factory.rb', line 7

def nudge_types
  @nudge_types
end

#original_options_hashObject (readonly)

Returns the value of attribute original_options_hash.



10
11
12
# File 'lib/factories/factory.rb', line 10

def original_options_hash
  @original_options_hash
end

#workstation_namesObject

Returns the value of attribute workstation_names.



9
10
11
# File 'lib/factories/factory.rb', line 9

def workstation_names
  @workstation_names
end

Class Method Details

.couch_available?Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
# File 'lib/factories/factory.rb', line 63

def self.couch_available?
  open(configatron.factory.couchdb.server).status
  true
rescue StandardError
  false 
end

Instance Method Details

#training_datasourceObject



70
71
72
# File 'lib/factories/factory.rb', line 70

def training_datasource
  "#{@couchdb_server}/#{@name}_training"
end

#update_configatron!Object

this apparent redundancy saves project-based and command-line overrides



52
53
54
55
56
57
58
59
60
# File 'lib/factories/factory.rb', line 52

def update_configatron!
  configatron.factory.name = @name
  configatron.nudge.instructions.all = @nudge_instructions
  configatron.nudge.types.all = @nudge_types
  configatron.factory.workstation_names = @workstation_names
  configatron.factory.couchdb.server = @couchdb_server
  configatron.factory.couchdb.name = @couchdb_name
  configatron.factory.training_datasource = self.training_datasource
end