Class: ComfortableMexicanSofa::Fixture::Importer
- Inherits:
-
Object
- Object
- ComfortableMexicanSofa::Fixture::Importer
- Defined in:
- lib/comfortable_mexican_sofa/fixture.rb
Direct Known Subclasses
Category::Importer, File::Importer, Layout::Importer, Page::Importer, Snippet::Importer
Instance Attribute Summary collapse
-
#fixture_ids ⇒ Object
Returns the value of attribute fixture_ids.
-
#force_import ⇒ Object
Returns the value of attribute force_import.
-
#from ⇒ Object
Returns the value of attribute from.
-
#path ⇒ Object
Returns the value of attribute path.
-
#site ⇒ Object
Returns the value of attribute site.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #fresh_fixture?(object, file_path) ⇒ Boolean
- #get_attributes(file_path) ⇒ Object
- #import! ⇒ Object
-
#initialize(from, to = from, force_import = false) ⇒ Importer
constructor
A new instance of Importer.
- #save_categorizations!(object, categories) ⇒ Object
Constructor Details
#initialize(from, to = from, force_import = false) ⇒ Importer
Returns a new instance of Importer.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/comfortable_mexican_sofa/fixture.rb', line 11 def initialize(from, to = from, force_import = false) self.from = from self.to = to self.site = Comfy::Cms::Site.where(:identifier => to).first! self.fixture_ids = [] self.force_import = force_import dir = self.class.name.split('::')[2].downcase.pluralize self.path = ::File.join(ComfortableMexicanSofa.config.fixtures_path, from, dir, '/') end |
Instance Attribute Details
#fixture_ids ⇒ Object
Returns the value of attribute fixture_ids.
4 5 6 |
# File 'lib/comfortable_mexican_sofa/fixture.rb', line 4 def fixture_ids @fixture_ids end |
#force_import ⇒ Object
Returns the value of attribute force_import.
4 5 6 |
# File 'lib/comfortable_mexican_sofa/fixture.rb', line 4 def force_import @force_import end |
#from ⇒ Object
Returns the value of attribute from.
4 5 6 |
# File 'lib/comfortable_mexican_sofa/fixture.rb', line 4 def from @from end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/comfortable_mexican_sofa/fixture.rb', line 4 def path @path end |
#site ⇒ Object
Returns the value of attribute site.
4 5 6 |
# File 'lib/comfortable_mexican_sofa/fixture.rb', line 4 def site @site end |
#to ⇒ Object
Returns the value of attribute to.
4 5 6 |
# File 'lib/comfortable_mexican_sofa/fixture.rb', line 4 def to @to end |
Instance Method Details
#fresh_fixture?(object, file_path) ⇒ Boolean
22 23 24 |
# File 'lib/comfortable_mexican_sofa/fixture.rb', line 22 def fresh_fixture?(object, file_path) object.new_record? || self.force_import || ::File.mtime(file_path) > object.updated_at end |
#get_attributes(file_path) ⇒ Object
26 27 28 |
# File 'lib/comfortable_mexican_sofa/fixture.rb', line 26 def get_attributes(file_path) YAML.load_file(file_path) || { } end |
#import! ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/comfortable_mexican_sofa/fixture.rb', line 43 def import! ComfortableMexicanSofa::Fixture::Category::Importer.new(from, to, force_import).import! ComfortableMexicanSofa::Fixture::Layout::Importer.new( from, to, force_import).import! ComfortableMexicanSofa::Fixture::Page::Importer.new( from, to, force_import).import! ComfortableMexicanSofa::Fixture::Snippet::Importer.new( from, to, force_import).import! ComfortableMexicanSofa::Fixture::File::Importer.new( from, to, force_import).import! end |
#save_categorizations!(object, categories) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/comfortable_mexican_sofa/fixture.rb', line 30 def save_categorizations!(object, categories) object.categorizations.delete_all [categories].flatten.compact.each do |label| category = self.site.categories.find_or_create_by( :label => label, :categorized_type => object.class.to_s ) category.categorizations.create!( :categorized => object ) end end |