Class: Adva::Static::Import::Model::Base
- Inherits:
-
Object
- Object
- Adva::Static::Import::Model::Base
- Defined in:
- lib/adva/static/import/model/base.rb
Instance Attribute Summary collapse
-
#attribute_names ⇒ Object
readonly
Returns the value of attribute attribute_names.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #attribute_name?(name) ⇒ Boolean
- #attributes ⇒ Object
- #body ⇒ Object
- #column_name?(name) ⇒ Boolean
-
#initialize(source) ⇒ Base
constructor
A new instance of Base.
- #load ⇒ Object
- #loadable ⇒ Object
- #model ⇒ Object
- #path ⇒ Object
- #site_id ⇒ Object
- #slug ⇒ Object
- #updated_at ⇒ Object
- #updated_record ⇒ Object
Constructor Details
#initialize(source) ⇒ Base
Returns a new instance of Base.
10 11 12 13 |
# File 'lib/adva/static/import/model/base.rb', line 10 def initialize(source) @source = source load end |
Instance Attribute Details
#attribute_names ⇒ Object (readonly)
Returns the value of attribute attribute_names.
8 9 10 |
# File 'lib/adva/static/import/model/base.rb', line 8 def attribute_names @attribute_names end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
8 9 10 |
# File 'lib/adva/static/import/model/base.rb', line 8 def source @source end |
Instance Method Details
#<=>(other) ⇒ Object
71 72 73 |
# File 'lib/adva/static/import/model/base.rb', line 71 def <=>(other) source <=> other.source end |
#==(other) ⇒ Object
67 68 69 |
# File 'lib/adva/static/import/model/base.rb', line 67 def ==(other) source == other end |
#attribute_name?(name) ⇒ Boolean
21 22 23 |
# File 'lib/adva/static/import/model/base.rb', line 21 def attribute_name?(name) attribute_names.include?(name.to_sym) end |
#attributes ⇒ Object
15 16 17 18 19 |
# File 'lib/adva/static/import/model/base.rb', line 15 def attributes attributes = attribute_names.map { |name| [name, self.send(name)] unless self.send(name).nil? } attributes = Hash[*attributes.compact.flatten_once] record && record.id ? attributes.merge(:id => record.id.to_s) : attributes end |
#body ⇒ Object
49 50 51 |
# File 'lib/adva/static/import/model/base.rb', line 49 def body @body || '' end |
#column_name?(name) ⇒ Boolean
25 26 27 |
# File 'lib/adva/static/import/model/base.rb', line 25 def column_name?(name) model.column_names.include?(name.to_s) end |
#load ⇒ Object
61 62 63 64 65 |
# File 'lib/adva/static/import/model/base.rb', line 61 def load if loadable.exist? format = Format.for(loadable) and format.load(self) end end |
#loadable ⇒ Object
57 58 59 |
# File 'lib/adva/static/import/model/base.rb', line 57 def loadable @loadable ||= source.full_path end |
#model ⇒ Object
33 34 35 |
# File 'lib/adva/static/import/model/base.rb', line 33 def model self.class.name.demodulize.constantize end |
#path ⇒ Object
45 46 47 |
# File 'lib/adva/static/import/model/base.rb', line 45 def path source.path end |
#site_id ⇒ Object
37 38 39 |
# File 'lib/adva/static/import/model/base.rb', line 37 def site_id site.id.to_s end |
#slug ⇒ Object
41 42 43 |
# File 'lib/adva/static/import/model/base.rb', line 41 def slug source.basename end |
#updated_at ⇒ Object
53 54 55 |
# File 'lib/adva/static/import/model/base.rb', line 53 def updated_at source.mtime end |
#updated_record ⇒ Object
29 30 31 |
# File 'lib/adva/static/import/model/base.rb', line 29 def updated_record record.tap { |record| record.attributes = attributes } end |