Module: HasProperties
- Included in:
- GitReference
- Defined in:
- lib/gpack/core/GitReference.rb
Instance Attribute Summary collapse
-
#props ⇒ Object
Returns the value of attribute props.
-
#require_attrs ⇒ Object
Returns the value of attribute require_attrs.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#props ⇒ Object
Returns the value of attribute props.
2 3 4 |
# File 'lib/gpack/core/GitReference.rb', line 2 def props @props end |
#require_attrs ⇒ Object
Returns the value of attribute require_attrs.
3 4 5 |
# File 'lib/gpack/core/GitReference.rb', line 3 def require_attrs @require_attrs end |
Class Method Details
.included(base) ⇒ Object
15 16 17 |
# File 'lib/gpack/core/GitReference.rb', line 15 def self.included base base.extend self end |
Instance Method Details
#has_properties(*args) ⇒ Object
5 6 7 8 9 |
# File 'lib/gpack/core/GitReference.rb', line 5 def has_properties *args @props = args instance_eval { attr_reader *args } instance_eval { attr_writer *args } end |
#has_required(*args) ⇒ Object
11 12 13 |
# File 'lib/gpack/core/GitReference.rb', line 11 def has_required *args @require_attrs = args end |
#initialize(args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gpack/core/GitReference.rb', line 19 def initialize(args) # Attributes required when defining a GitReference require_attrs = self.class.require_attrs # Check that all the required args.each do |k,v| require_attrs = require_attrs - [k] end if require_attrs.any? raise "Must include attributes #{require_attrs} in GitReference definition" end args.each {|k,v| instance_variable_set "@#{k}", v if self.class.props.member?(k) } if args.is_a? Hash end |