Class: Easyfire::EasyfireModel

Inherits:
Object
  • Object
show all
Defined in:
lib/easyfire/easyfire_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEasyfireModel

Returns a new instance of EasyfireModel.



17
18
19
# File 'lib/easyfire/easyfire_model.rb', line 17

def initialize()
  @spec = ModelSpec.new
end

Instance Attribute Details

#specObject

Returns the value of attribute spec.



15
16
17
# File 'lib/easyfire/easyfire_model.rb', line 15

def spec
  @spec
end

Instance Method Details

#attribute(attribute_name, &block) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/easyfire/easyfire_model.rb', line 101

def attribute(attribute_name, &block)
  @attribute_name = attribute_name
  new_attribute = {
    description: "",
    example: "",
    type: nil,
    options: [],
    association: nil
  }

  unless self.respond_to? :attr_association
    def attr_association(value)
      @spec.attributes[@attribute_name][:association] = value
    end
  
    def attr_options(options)
      @spec.attributes[@attribute_name][:options] = options
    end
    
    def attr_example(text)
      @spec.attributes[@attribute_name][:example] = text
    end

    def attr_description(text)
     @spec.attributes[@attribute_name][:description] = text
    end

    def attr_data_type(symbol)
      @spec.attributes[@attribute_name][:type] = symbol
    end
  end
  
  
  @spec.attributes[@attribute_name] = new_attribute
  block.call
end

#belongs_to(bt_name, &block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/easyfire/easyfire_model.rb', line 49

def belongs_to(bt_name, &block)
  
  @bt_name = bt_name

  new_association = {
    type: :belongs_to,
    description: "",
    example: "",
    navigable: false,
    load: :lazy
  }

  unless self.respond_to? :bt_navigable
    
    def bt_navigable(value)
      @spec.associations[@bt_name][:navigable] = value
    end
  
    def bt_load(value)
      @spec.associations[@bt_name][:load] = value
    end

    def bt_example(text)
      @spec.associations[@bt_name][:example] = text
    end

    def bt_description(text)
      @spec.associations[@bt_name][:description] = text
    end
    
  end

  @spec.associations[@bt_name] = new_association
  block.call
  
  
  proc = Proc.new do
      attr_description ""
      attr_data_type :String
  end
  attribute("#{bt_name.to_s.uncapitalize}EFPath".to_sym,&proc)

  proc = Proc.new do
      attr_description ""
      attr_data_type "#{bt_name}EF"
      attr_options [:transient]
      attr_association bt_name
  end

  attribute("#{bt_name.to_s.uncapitalize}EF".to_sym,&proc)
end

#child(child_class) ⇒ Object



43
44
45
# File 'lib/easyfire/easyfire_model.rb', line 43

def child(child_class)
  @@spec.child = child_class
end

#compile(&block) ⇒ Object



21
22
23
24
# File 'lib/easyfire/easyfire_model.rb', line 21

def compile(&block)
  instance_eval(&block)
  return @spec
end

#description(text) ⇒ Object



34
35
36
# File 'lib/easyfire/easyfire_model.rb', line 34

def description(text)
  @spec.description = text
end

#model_name(text) ⇒ Object



26
27
28
# File 'lib/easyfire/easyfire_model.rb', line 26

def model_name(text)
  @spec.model_name = text
end

#model_type(value) ⇒ Object



38
39
40
# File 'lib/easyfire/easyfire_model.rb', line 38

def model_type(value)
  @spec.model_type = value
end

#parents(value) ⇒ Object



30
31
32
# File 'lib/easyfire/easyfire_model.rb', line 30

def parents(value)
  @spec.parents = value
end