Class: Adva::Static::Import::Format::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/adva/static/import/format.rb

Direct Known Subclasses

Jekyll, Yml

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Base

Returns a new instance of Base.



13
14
15
# File 'lib/adva/static/import/format.rb', line 13

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/adva/static/import/format.rb', line 11

def path
  @path
end

Instance Method Details

#define_attribute(target, name) ⇒ Object



28
29
30
31
32
# File 'lib/adva/static/import/format.rb', line 28

def define_attribute(target, name)
  target.attribute_names << name
  target.attribute_names.uniq!
  target.class.send(:attr_reader, name) unless target.respond_to?(name)
end

#define_attribute?(target, name) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/adva/static/import/format.rb', line 24

def define_attribute?(target, name)
  !target.attribute_name?(name) && target.column_name?(name)
end

#load(target) ⇒ Object



17
18
19
20
21
22
# File 'lib/adva/static/import/format.rb', line 17

def load(target)
  data.each do |name, value|
    define_attribute(target, name) if define_attribute?(target, name)
    target.instance_variable_set(:"@#{name}", value)
  end if data.is_a?(Hash)
end