Class: Spout::Models::Domain
- Defined in:
- lib/spout/models/domain.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#folder ⇒ Object
Returns the value of attribute folder.
-
#id ⇒ Object
Returns the value of attribute id.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #deploy_params ⇒ Object
-
#initialize(file_name, dictionary_root) ⇒ Domain
constructor
A new instance of Domain.
Methods inherited from Record
Constructor Details
#initialize(file_name, dictionary_root) ⇒ Domain
Returns a new instance of Domain.
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 |
# File 'lib/spout/models/domain.rb', line 14 def initialize(file_name, dictionary_root) @errors = [] @id = file_name.to_s.gsub(/^(.*)\/|\.json$/, "").downcase @folder = file_name.to_s.gsub(/^#{dictionary_root}\/domains\/|#{@id}\.json$/, "") @options = [] json = begin if File.exist?(file_name) JSON.parse(File.read(file_name, encoding: "utf-8")) else @errors << "No corresponding #{@id}.json file found." nil end rescue => e @errors << "Parsing error found in #{@id}.json: #{e.}" unless file_name.nil? nil end if json.is_a? Array @id = file_name.to_s.gsub(/^(.*)\/|\.json$/, "").downcase @options = (json || []).collect do |option| Spout::Models::Option.new(option) end elsif json @errors << "Domain must be a valid array in the following format: [\n {\n \"value\": \"1\",\n \"display_name\": \"First Choice\",\n \"description\": \"First Description\"\n },\n {\n \"value\": \"2\",\n \"display_name\": \"Second Choice\",\n \"description\": \"Second Description\"\n }\n]" end end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
12 13 14 |
# File 'lib/spout/models/domain.rb', line 12 def errors @errors end |
#folder ⇒ Object
Returns the value of attribute folder.
11 12 13 |
# File 'lib/spout/models/domain.rb', line 11 def folder @folder end |
#id ⇒ Object
Returns the value of attribute id.
11 12 13 |
# File 'lib/spout/models/domain.rb', line 11 def id @id end |
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/spout/models/domain.rb', line 11 def @options end |