Class: Simplifyapi::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/simplifyapi/property.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Property

Returns a new instance of Property.



5
6
7
8
9
# File 'lib/simplifyapi/property.rb', line 5

def initialize name, &block
  @name = name

  instance_eval &block if block_given?
end

Instance Attribute Details

#getterObject (readonly)

Returns the value of attribute getter.



3
4
5
# File 'lib/simplifyapi/property.rb', line 3

def getter
  @getter
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/simplifyapi/property.rb', line 3

def name
  @name
end

#setterObject (readonly)

Returns the value of attribute setter.



3
4
5
# File 'lib/simplifyapi/property.rb', line 3

def setter
  @setter
end

Instance Method Details

#export(model) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/simplifyapi/property.rb', line 19

def export model
  if getter_defined?
    @getter.call model
  else
    model.send name
  end
end

#getter_defined?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/simplifyapi/property.rb', line 27

def getter_defined?
  !!@getter
end

#import(model, value) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/simplifyapi/property.rb', line 11

def import model, value
  if setter_defined?
    @setter.call model, value
  else
    model.send "#{name}=", value
  end
end

#setter_defined?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/simplifyapi/property.rb', line 31

def setter_defined?
  !!@setter
end